using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;

namespace OpenNETCF
{
    public partial class MonthDemo : Form
    {
        Bitmap alarm;

        public MonthDemo()
        {
            using (new OpenNETCF.Windows.Forms.Cursor2())
            {
                InitializeComponent();
                this.monthCalendar1.SelectedDate = DateTime.Now;
                //Draw label is called first.  This is used to custom draw the label.
                this.monthCalendar1.DrawLabel += new OpenNETCF.Windows.Forms.Calendar.DrawLabelHandler(monthCalendar1_DrawLabel);

                //Get label is called if there is no custom drawing.  Here you just return a string for the label you want to display.
                //If custom drawing is enabled GetLabel will never be called.
                this.monthCalendar1.GetLabel += new OpenNETCF.Windows.Forms.Calendar.GetLabelHandler(monthCalendar1_GetLabel);

                //Get the alarm image
                alarm = new Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("CalendarSample.alarm.bmp"));
            }
        }

        

        /// <summary>
        /// Custom drawing for the cell.  Can use this to draw an icon to display an appointment etc
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="date"></param>
        /// <param name="rectCell"></param>
        /// <param name="gxCell"></param>
        private void monthCalendar1_DrawLabel(OpenNETCF.Windows.Forms.Calendar.BaseCalendar sender, DateTime date, Rectangle rectCell, Graphics gxCell)
        {
            if (date.Date == DateTime.Now.Date)
            {
                //Draw a square in the bottom right corner.
                using(SolidBrush br = new SolidBrush(SystemColors.Control))
                   gxCell.FillRectangle(br, rectCell.X + rectCell.Width - 10, rectCell.Y + rectCell.Height - 10, 9, 9);
            }

            if (date.Date.ToShortDateString() == DateTime.Now.AddDays(1).ToShortDateString())
            {
                //Draw an icon
                Rectangle dest = new Rectangle(rectCell.X + rectCell.Width - this.alarm.Width,
                    rectCell.Y + rectCell.Height - this.alarm.Height,
                    this.alarm.Width, this.alarm.Height);

                ImageAttributes ia = new ImageAttributes();
                ia.SetColorKey(this.alarm.GetPixel(0,0),this.alarm.GetPixel(0,0));
                gxCell.DrawImage(this.alarm, dest, 0, 0, this.alarm.Width, this.alarm.Height, GraphicsUnit.Pixel, ia);

            }

        }

        private string monthCalendar1_GetLabel(DateTime date)
        {
            if (date.Date == DateTime.Now.Date)
                return "Today";
            return "";
        }

       
    }
}
